-- Drop Existing Procedures

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_Insert]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_Insert]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_Update]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_Update]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_InsertUpdate]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_InsertUpdate]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_Delete]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_Delete]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_DeleteDynamic]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteDynamic]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_Load]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_Load]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_SelectDynamic]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectDynamic]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_SelectAll]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectAll]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_SelectBy_ProjectID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_ProjectID]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_SelectBy_ID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_ID]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_SelectBy_GroupID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_GroupID]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_SelectBy_TaskID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_TaskID]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_DeleteBy_ProjectID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_ProjectID]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_DeleteBy_ID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_ID]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_DeleteBy_GroupID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_GroupID]

IF OBJECT_ID(N'[dbo].[p_ACTP_ProjectTask_DeleteBy_TaskID]') IS NOT NULL
	DROP PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_TaskID]


GO


------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_Insert]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_Insert]
	@ModuleID uniqueidentifier,
	@ProjectID int,
	@GroupID int,
	@TaskID int,
	@ID int OUTPUT
AS

INSERT INTO [dbo].[t_ACTP_ProjectTasks]
(
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
)
VALUES 
(
	@ModuleID,
	@ProjectID,
	@GroupID,
	@TaskID
)

SET @ID = SCOPE_IDENTITY()

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_Update]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_Update]
	@ID int,
	@ModuleID uniqueidentifier,
	@ProjectID int,
	@GroupID int,
	@TaskID int
AS

UPDATE
	[dbo].[t_ACTP_ProjectTasks]
SET
	[ModuleID] = @ModuleID,
	[ProjectID] = @ProjectID,
	[GroupID] = @GroupID,
	[TaskID] = @TaskID
WHERE
	[ID] = @ID

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_InsertUpdate]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_InsertUpdate]
	@ID int,
	@ModuleID uniqueidentifier,
	@ProjectID int,
	@GroupID int,
	@TaskID int
AS
IF EXISTS(SELECT [ID] FROM [dbo].[t_ACTP_ProjectTasks] WHERE [ID] = @ID)
	BEGIN
		UPDATE
			[dbo].[t_ACTP_ProjectTasks] 
		SET
			[ModuleID] = @ModuleID,
			[ProjectID] = @ProjectID,
			[GroupID] = @GroupID,
			[TaskID] = @TaskID
		WHERE
			[ID] = @ID
	END
ELSE
	BEGIN
		
		INSERT INTO [dbo].[t_ACTP_ProjectTasks]
		(
			[ModuleID],
			[ProjectID],
			[GroupID],
			[TaskID]
		)
		VALUES 
		(
			@ModuleID,
			@ProjectID,
			@GroupID,
			@TaskID
		)		
	END
GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_Delete]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_Delete]
	@ID int
AS

DELETE FROM 
	[dbo].[t_ACTP_ProjectTasks]
WHERE
	[ID] = @ID

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_DeleteBy_ProjectID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_ProjectID]
	@ProjectID int
AS

DELETE FROM [dbo].[t_ACTP_ProjectTasks]
WHERE
	[ProjectID] = @ProjectID

GO

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_DeleteBy_ID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_ID]
	@ID int
AS

DELETE FROM [dbo].[t_ACTP_ProjectTasks]
WHERE
	[ID] = @ID

GO

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_DeleteBy_GroupID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_GroupID]
	@GroupID int
AS

DELETE FROM [dbo].[t_ACTP_ProjectTasks]
WHERE
	[GroupID] = @GroupID

GO

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_DeleteBy_TaskID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteBy_TaskID]
	@TaskID int
AS

DELETE FROM [dbo].[t_ACTP_ProjectTasks]
WHERE
	[TaskID] = @TaskID

GO

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_DeleteDynamic]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_DeleteDynamic]
	@WhereCondition NVARCHAR(500)
AS

DECLARE @SQL NVARCHAR(MAX)

SET @SQL = 'DELETE FROM [dbo].[t_ACTP_ProjectTasks] WHERE ' + @WhereCondition

EXEC sp_executesql @SQL

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_Load]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_Load]
	@ID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
FROM
	[dbo].[t_ACTP_ProjectTasks]
WHERE
	[ID] = @ID
GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_SelectBy_ProjectID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_ProjectID]
	@ProjectID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
FROM
	[dbo].[t_ACTP_ProjectTasks]
WHERE
	[ProjectID] = @ProjectID

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_SelectBy_ID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_ID]
	@ID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
FROM
	[dbo].[t_ACTP_ProjectTasks]
WHERE
	[ID] = @ID

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_SelectBy_GroupID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_GroupID]
	@GroupID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
FROM
	[dbo].[t_ACTP_ProjectTasks]
WHERE
	[GroupID] = @GroupID

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_SelectBy_TaskID]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectBy_TaskID]
	@TaskID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
FROM
	[dbo].[t_ACTP_ProjectTasks]
WHERE
	[TaskID] = @TaskID

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_SelectDynamic]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectDynamic]
	@WhereCondition NVARCHAR(500),
	@OrderByExpression NVARCHAR(250) = NULL
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

DECLARE @SQL NVARCHAR(MAX)

SET @SQL = 
'SELECT 
	[ID],
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
FROM [dbo].[t_ACTP_ProjectTasks] 
WHERE ' + @WhereCondition

IF @OrderByExpression IS NOT NULL AND LEN(@OrderByExpression) > 0
BEGIN
	SET @SQL = @SQL + ' ORDER BY ' + @OrderByExpression
END

EXEC sp_executesql @SQL

GO

------------------------------------------------------------------------------------------------------------------------
-- Stored procedure name: [dbo].[p_ACTP_ProjectTask_SelectAll]
-- Database: ASPNETVN.PORTAL
-- Author: Ngo Thanh Tung
-- Time created: Monday, October 04, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[p_ACTP_ProjectTask_SelectAll]
	@ModuleID UNIQUEIDENTIFIER
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[ModuleID],
	[ProjectID],
	[GroupID],
	[TaskID]
FROM
	[dbo].[t_ACTP_ProjectTasks]	
WHERE 
	(ModuleID = @ModuleID)

GO

